<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>0414-02 3D切割轮播图</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
            margin:50px auto;
            width: 800px;
            display: flex;
            border: 1px solid #000;
            height: 500px;
        }
        li{
            /*flex: 1;*/
            width: 160px;
            transform-style:preserve-3d;
            position: relative;
            /*transform:rotateY(1deg) rotateZ(10deg)*/
        }
        span{
            position: absolute;
            left:0;
            top:0;
            width: 100%;
            height: 100%;
            background-size:cover;
        }


        li span:nth-child(1){
            transform: translateZ(250px);
        }
        li span:nth-child(2){
            transform: translateY(-250px) rotateX(90deg);
        }
        li span:nth-child(3){
            transform: translateZ(-250px) rotateX(180deg);
        }
        li span:nth-child(4){
            transform: translateY(250px) rotateX(-90deg);
        }
        /*四个图*/
        li span:nth-child(1){
            background: url("../img/2.png") no-repeat;
        }
        li span:nth-child(2){
            background: url("../img/3.png") no-repeat;
        }
        li span:nth-child(3){
            background: url("../img/6.png") no-repeat;
        }
        li span:nth-child(4){
            background: url("../img/7.png") no-repeat;
        }

        li:nth-child(1) span{
            background-size:cover;
        }
        li:nth-child(2) span{
            background-position: -160px 0;
            background-size:cover;
        }
        li:nth-child(3) span{
            background-position: -320px 0;
            background-size:cover;
        }
        li:nth-child(4) span{
            background-position: -480px 0;
            background-size:cover;
        }
        li:nth-child(5) span{
            background-position: -640px 0;
            background-size:cover;
        }


        /*按钮*/
        a{
            text-decoration: none;
            color:#000;
            background-color: #ccc;
            font-size:40px;
            position: absolute;
            left:40%;
            width: 80px;
            height: 50px;
            line-height: 50px;
            text-align: center;
            text-shadow: 1px 1px 2px #555;
        }
        .btn2{
            left:auto;
            right:40%;
        }
    </style>
</head>
<body>
<ul>
    <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </li>
    <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </li>
    <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </li>
    <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </li>
    <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </li>
</ul>
<a href="javascript:;" class="btn1">←</a>
<a href="javascript:;" class="btn2">→</a>
<script src="../js/jquery-1.12.2.min.js"></script>
<script>
    $(function () {
        var index = 0;
        var flag = true;
        $("li").each(function (index,ele) {
            $("li").eq(index).css("transition-delay",index*0.1+"s")
        })
        $(".btn1").click(function () {
            if (flag) {
                index++;
                flag = false;
                $("li").css({
                    "transform":"rotateX("+90*index+"deg)",
                    "transition-property":"transform",
                    "transition-duration":"1s"
                })
                $("li").eq(4).on("transitionend",function () {   /*出现问题的原因是on绑定的事件不会覆盖之前绑定的事件*/
                    flag = true
                })
            }
        })
//        右边按钮
        $(".btn2").click(function () {
            if (flag) {
                index--;
                flag = false;
                $("li").css({
                    "transform":"rotateX("+90*index+"deg)",
                    "transition-property":"transform",
                    "transition-duration":"1s"
                })
                $("li").eq(4).on("transitionend",function () {
                    flag = true
                })
            }
        })

    })
</script>
</body>
</html>













